#!/bin/sh
#######################################################################################
# Name:          bashrc.mingw
# Description:   Environemnt setup script for use with MSYS shell for MinGW-based build
# Author:        Cesare Guardino
# Last modified: 19 January 2016
#
# GE CONFIDENTIAL INFORMATION ?2016 General Electric Company - All Rights Reserved
#######################################################################################
export HOME=/H/vc  #ligb 20180423 set project home dir
export ARPACK_HOME=$HOME/ARPACK
export ARCH=x64   #ligb 20180422 set ARCH=x64 for 64bit
#export ARCH=x86

export PROGRAMS_HOME="/h/Program Files"

# {{{ DEFINE USER EDITABLE FUNCTIONS
set_system_paths() {
    echo "Setting environment variables for user-defined installed system tools and utilities ..."
    #export CMAKE_HOME=$PROGRAMS_HOME/cmake-3.2.3-win32-x86
    #export GIT_HOME=$PROGRAMS_HOME/Git
    #export JAVA_HOME="/c/Program Files/Java/jre1.8.0_45"
    export GNUPLOT_HOME=$PROGRAMS_HOME/gp501-win64-mingw
    export IMAGEMAGICK_HOME=$PROGRAMS_HOME/ImageMagick-6.9.1-2

	if [ $ARCH = x64 ] ; then
		#export MINGW_HOME="/h/Program Files/mingw-w64/x86_64-7.3.0-win32-seh-rt_v5-rev0/mingw64" #this make errors
		#export MINGW_HOME="/h/Program Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev1/mingw64"	
		export MINGW_HOME="/c/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev1/mingw64"
		export PLAT=MINGW64
		export GLUT=glut64
	else
		export MINGW_HOME="/H/mingw-w64/i686-4.9.3-win32-sjlj-rt_v4-rev1/mingw32"
		export PLAT=MINGW32
		export GLUT=glut32
	fi

    #export MPI_ROOTDIR=$PROGRAMS_HOME/OpenMPI_v1.6.1-x64
    #export PARAVIEW_HOME=$PROGRAMS_HOME/ParaView-4.3.1
	export PERL_HOME=$PROGRAMS_HOME/strawberry-perl-5.20.2.1-64bit/perl
    #export PERL_HOME=c/MinGW/msys/1.0 #这个perl有问题，导致编译出错
    #export PEXPORTS_HOME=$PROGRAMS_HOME/pexports-0.46-mingw32
    #export PYTHON_HOME=$PROGRAMS_HOME/Python27
    #export SUBVERSION_HOME=$PROGRAMS_HOME/svn-win32-1.8.13
    export WGET_HOME=$PROGRAMS_HOME/wget-1.11.4-1
    export ZIP_HOME="/c/Program Files/7-Zip"
	#added the flowing by ligb 20180425
	export GLUT_DLL=$HOME/glut-3.7.6-bin-32and64/GL
	export PTHREADS_DLL=$HOME/pthreads-w32-2-9-1-release/Pre-built.2/dll/$ARCH
}

add_to_path() {
    echo
    echo "Adding user-defined installed system tools to PATH ..."
    export PATH=$ZIP_HOME:$PATH
    export PATH=$WGET_HOME/bin:$PATH
    export PATH=$GNUPLOT_HOME/bin:$PATH
    export PATH=$IMAGEMAGICK_HOME:$PATH
    #export PATH=$JAVA_HOME/bin:$PATH
    #export PATH=$PYTHON_HOME:$PATH
    #export PATH=$SUBVERSION_HOME/bin:$PATH
    #export PATH=$GIT_HOME/cmd:$PATH
    #export PATH=$PARAVIEW_HOME/bin:$PATH
    export PATH=$PERL_HOME/bin:$PATH
    #export PATH=$CMAKE_HOME/bin:$PATH
    #export PATH=$MPI_ROOTDIR/bin:$PATH
    #export PATH=$PEXPORTS_HOME/bin:$PATH
    export PATH=$MINGW_HOME/bin:$PATH
	#added the flowing by ligb 20180425
	#加了下句出现多线程编译错误
	#export PATH=$PTHREADS_DLL:$GLUT_DLL:$PATH 
}
# }}}

# {{{ DEFINE PROCESS FUNCTIONS
setup_calculix_env() {
    echo
    CALCULIX_ETC_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
    CALCULIX_HOME=$(readlink -f $CALCULIX_ETC_DIR/..)
    export PATH=$CALCULIX_HOME/$(ARCH)/install:$PATH
}

check_versions() {
    echo
    echo "Checking versions of installed system tools (based on PATH) ..."
    echo "7-Zip:      " `which 7z`       [`(7z --help 2>&1) 2> /dev/null | head -2`]
    #echo "Bison:      " `which bison`    [`(bison --version 2>&1) 2> /dev/null | head -1`]
    echo "CMake:      " `which cmake`    [`(cmake --version 2>&1) 2> /dev/null | head -1`]
    #echo "Flex:       " `which flex`     [`(flex --version 2>&1) 2> /dev/null | head -1`]
    echo "G++:        " `which g++`      [`(g++ --version 2>&1) 2> /dev/null | head -1`]
    echo "GCC:        " `which gcc`      [`(gcc --version 2>&1) 2> /dev/null | head -1`]
    echo "GFortran:   " `which gfortran` [`(gfortran --version 2>&1) 2> /dev/null | head -1`]
    echo "GMake:      " `which gmake`    [`(gmake --version 2>&1) 2> /dev/null | head -1`]
    #echo "Git:        " `which git`      [`(git --version 2>&1) 2> /dev/null | head -1`]
    echo "Gnuplot:    " `which gnuplot`  [`(gnuplot --version 2>&1) 2> /dev/null | head -1`]
    echo "ImageMagick:" `which convert`  [`(convert --version 2>&1) 2> /dev/null | head -1`]
    #echo "Java:       " `which java`     [`(java -version 2>&1) 2> /dev/null | head -1`]
    #echo "M4:         " `which m4`       [`(m4 --version 2>&1) 2> /dev/null | head -1`]
    echo "Make:       " `which make`     [`(make --version 2>&1) 2> /dev/null | head -1`]
    #echo "MinGW-w64:  " $MINGW_HOME
    #echo "OpenMPI:    " `which mpirun`   [`(mpirun --version 2>&1) 2> /dev/null | head -1`]
    #echo "PEexports:  " `which pexports` [`(pexports -v 2>&1) 2> /dev/null | head -1`]
    #echo "ParaView:   " $PARAVIEW_HOME
    echo "Perl:       " `which perl`     [`(perl -v 2>&1) 2> /dev/null | head -2`]
    echo "Python:     " `which python`   [`(python --version 2>&1) 2> /dev/null | head -1`]
    #echo "Subversion: " `which svn`      [`(svn --version 2>&1) 2> /dev/null | head -1`]
    echo "Vim:        " `which vim`      [`(vim --version 2>&1) 2> /dev/null | head -1`]
    echo "Wget:       " `which wget`     [`(wget --version 2>&1) 2> /dev/null | head -3`]
}

finish() {
    echo
    echo
    echo "ENVIRONMENT SETUP COMPLETE."
}
# }}}

# {{{ MAIN EXECUTION
set_system_paths
setup_calculix_env
add_to_path
check_versions
finish
# }}}

